package com.oscar.ehome.view.setview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.StudyListBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.dowload.progressbar.RoundProgressBar;

import org.apache.commons.collections.MapUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/21
 * 下载列表页
 */

public class MyDownLoadAdapter extends BaseAdapter {

    private ArrayList<StudyListBean> list;
    List<Map<String, Object>> tempData = new ArrayList<Map<String, Object>>();
    private LayoutInflater mInflater;
    private Context mContext = null;

//    public MyDownLoadAdapter(Context context, ArrayList<StudyListBean> list) {
//        this.mContext = context;
//        this.list = list;
//        mInflater = LayoutInflater.from(context);
//    }

    public MyDownLoadAdapter(Context context, List<Map<String, Object>> tempData) {
        this.mContext = context;
        this.tempData = tempData;
        mInflater = LayoutInflater.from(context);
    }

    public void setList(List<Map<String, Object>> tempData) {
        this.tempData = tempData;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return tempData.size();
    }

    @Override
    public Object getItem(int position) {
        return tempData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_mydownload, null);
            holder = new ViewHolder();
            holder.mydownlist_title = (TextView) convertView.findViewById(R.id.mydownlist_title);
            holder.mydownlist_size = (TextView) convertView.findViewById(R.id.mydownlist_size);
            holder.mydownlist_img = (ImageView) convertView.findViewById(R.id.mydownlist_img);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (tempData.size() > 0) {
            Map<String, Object> map = tempData.get(position);
            if (map != null) {
                holder.mydownlist_title.setText(MapUtils.getString(map, "title"));
                holder.mydownlist_size.setText(MapUtils.getString(map, "size"));
                String img = MapUtils.getString(map, "imgdata");
                if (img != null)
//                GildeUtils.imgLoadPic(mContext, img, holder.mydownlist_img, "net");
                GildeUtils.loadUrlImages(img, holder.mydownlist_img, mContext);
            }
        }

        return convertView;
    }


    class ViewHolder {
        TextView mydownlist_title;//标题
        ImageView mydownlist_img;//图片
        TextView mydownlist_size;//大小
    }

}
